package com.rfchina.okr.xianren.controller.api;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.jfinal.core.Controller;
import com.jfinal.kit.StrKit;
import com.jfinal.plugin.redis.Redis;
import com.rfchina.okr.xianren.util.MyUtil;

public class ApiLoginInterceptor implements Interceptor {

	private static Logger logger = LoggerFactory.getLogger(ApiLoginInterceptor.class);

	public void intercept(Invocation inv) {

		Controller conn = inv.getController();
		String token = conn.getPara("access_token");
 

		MyUtil.verification(StrKit.isBlank(token), "access_token不能为空");
		Long uid = Redis.use().get(token);
		logger.info("access_token:{},uid:{}",token,uid);
		if (uid == null) {
			MyUtil.error(410, "用户没有登录");
		}
		conn.setAttr("__uid", uid);

		inv.invoke();

	}

}
